from flask import Blueprint, render_template

view = Blueprint('view', __name__)


@view.route('/user', methods=['POST', 'GET'])
def index():
    user = 'guest'
    title = 'hello world'
    list1 = list(range(10))
    my_list = [
        {"id": 1, "value": "我爱工作"},
        {"id": 2, "value": "工作使人快乐"},
        {"id": 3, "value": "沉迷于工作无法自拔"},
        {"id": 4, "value": "日渐消瘦"},
        {"id": 5, "value": "以梦为马，越骑越傻"}
    ]
    # 使用render_template()方法重定向到templates文件夹下查找post.html文件
    return render_template('user.html', title=title, name=user, my_list=my_list, list2=list1)


@view.route('/user-profile')
def profile():
    return 'The profile page'


@view.route('/user/<user>')
def get_user(user):
    return 'Get user: %s' % user


@view.route('/user/<user>', methods=['POST'])
def set_user(user):
    return 'Set user: %s' % user


@view.route('/post/<int:post_id>')
def show_post(post_id):
    # show the post with the given id, the id is an integer
    return 'Post: %d' % post_id
